<?php

namespace backend\modules\pooai\models\search;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\pooai\models\ZpooaiGallImages;

/**
 * ZpooaiGallImagesSearch represents the model behind the search form about `backend\modules\pooai\models\ZpooaiGallImages`.
 */
class ZpooaiGallImagesSearch extends ZpooaiGallImages
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['pooai_gall_images_id', 'zpooai_pages_id', 'zpooai_image'], 'safe'],
            [['sort_number'], 'integer'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = ZpooaiGallImages::find()->orderBy(['sort_number'=>SORT_ASC]);

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'sort_number' => $this->sort_number,
        ]);

        $query->andFilterWhere(['like', 'pooai_gall_images_id', $this->pooai_gall_images_id])
            ->andFilterWhere(['like', 'zpooai_pages_id', $this->zpooai_pages_id])
            ->andFilterWhere(['like', 'zpooai_image', $this->zpooai_image]);

        return $dataProvider;
    }
}
